package routing;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

/**
 * @author wangjinqiang
 * @date 2019-08-08
 */
public class EmitLogDirect {
    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("localhost");
        try (final Connection connection = connectionFactory.newConnection()) {
            final Channel channel = connection.createChannel();
            channel.exchangeDeclare(EXCHANGE_NAME, "direct");

            String serverity = "info";
            String message = "Run. Run. Or it will explode.";
            channel.basicPublish(EXCHANGE_NAME, serverity, null, message.getBytes(StandardCharsets.UTF_8));
            System.out.println(" [x] Sent '" + serverity + "':'" + message + "'");
        }
    }
}
